package org.devocean.groupbuying.service.impl;

import java.util.List;

import org.devocean.groupbuying.dao.FormulaDAO;
import org.devocean.groupbuying.domain.Formula;
import org.devocean.groupbuying.service.FormulaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class FormulaServiceImpl implements FormulaService {

	@Autowired
	private FormulaDAO formulaDAO;

	@Transactional(readOnly = true)
	public Formula getFormulaById(Integer formulaID) {

		return formulaDAO.findFormulaById(formulaID);
	}

	@Transactional
	public Formula addOrUpdateFormula(Formula formula) {
		if (formula.getFormulaID() == null) {
			return formulaDAO.saveFormula(formula);
		} else {
			return formulaDAO.updateFormula(formula);
		}

	}

	@Transactional
	public void removeFormula(Integer formulaID) {
		formulaDAO.deleteFormula(formulaID);
	}

	public long countFormulas() {
		return formulaDAO.countFormula();
	}

	@Transactional
	public List<Formula> getAllFormulas() {
		return formulaDAO.findAllFormulas();
	}

	

}
